package com.atguigu.yygh.hosp.controller.user;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author mgx
 * @version 1.0
 * @description: 前台医院界面
 * @date 2022/8/30 18:53
 */
@Api(tags = "医院显示接口")
@RestController
@RequestMapping("/user/hosp/hospital")
public class UserHospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation(value = "前台查看医院信息列表")
    @GetMapping("/list")
    public R getHospitalList(HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> page = hospitalService.getHospitalPage(1, 1000000, hospitalQueryVo);
        return R.ok().data("list", page.getContent());
    }

    @ApiOperation(value = "前台根据名字模糊查询医院信息列表")
    @GetMapping("/{hosname}")
    public R findHospitalByHosName(@PathVariable("hosname") String hosname) {
        List<Hospital> list = hospitalService.findByName(hosname);
        return R.ok().data("list", list);
    }

    @ApiOperation(value = "根据医院编号获取医院详情信息")
    @GetMapping("/detail/{hoscode}")
    public R findHospitalByHoscode(@PathVariable("hoscode") String hoscode) {
        Hospital hospital = hospitalService.findByHoscode(hoscode);
        return R.ok().data("hospital", hospital);
    }
}
